package shell

import (
	"fmt"
	"golang.org/x/crypto/ssh"
	"time"
)

func Login(host, user, password string, port int) (client *ssh.Client, err error) {
	config := &ssh.ClientConfig{
		Timeout:         time.Second, //ssh 连接time out 时间一秒钟, 如果ssh验证错误 会在一秒内返回
		User:            user,
		HostKeyCallback: ssh.InsecureIgnoreHostKey(), //这个可以, 但是不够安全
		Auth:            []ssh.AuthMethod{ssh.Password(password)},
	}

	//dial 获取ssh client
	addr := fmt.Sprintf("%s:%d", host, port)
	return ssh.Dial("tcp", addr, config)
}
